﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using LibService.DTO;

namespace LibService.DAO
{
    public class DichVuDAO
    {
        #region 1. Lay Danh Sach Thong Tin Dich Vu
        public static List<DichVuDTO> layDanhSachDichVu()
        {
            List<DichVuDTO> lst = new List<DichVuDTO>();
            try
            {
                SQLConnect cnn = new SQLConnect();
                DataTable dt = new DataTable();
                //String strSQL = "SELECT * FROM DICHVU";
                dt = cnn.ExecuteQuery("sp_layThongTinDichVu", CommandType.StoredProcedure);
                //dataAdapter.Fill(dt);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DichVuDTO dv = new DichVuDTO();
                    dv.MaDichVu = dt.Rows[i]["MaDichVu"].ToString();
                    dv.TenDichVu = dt.Rows[i]["TenDichVu"].ToString();
                    lst.Add(dv);
                }
            }
            catch (Exception ex)
            {

            }
            return lst;
        }
        #endregion

        #region 2. Lay thong tin dich vu theo ma
        public static DichVuDTO layThongTinDichVuTheoMa(String maDichVu)
        {
            DichVuDTO dv = new DichVuDTO();
            try
            {
                SQLConnect cnn = new SQLConnect();
                DataTable dt = new DataTable();
                dt = cnn.ExecuteQuery("", CommandType.Text);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dv.MaDichVu = dt.Rows[i]["MaDichVu"].ToString();
                    dv.TenDichVu = dt.Rows[i]["TenDichVu"].ToString();
                }
            }
            catch(Exception ex){}
            return dv;
        }
        #endregion

        #region 3. Them thong tin dich vu
        public static bool InsertDichVu(DichVuDTO dv)
        {
            bool result = false;
            try
            {
                SQLConnect cnn = new SQLConnect();
                List<SqlParameter> sqlPar = new List<SqlParameter>();
                sqlPar.Add(new SqlParameter("@maDichVu", dv.MaDichVu));
                sqlPar.Add(new SqlParameter("@tenDichVu", dv.TenDichVu));

                int n = cnn.ExecuteNonQuery("",CommandType.StoredProcedure,sqlPar);

                if (n == 1)
                {
                    result = true;
                }
            }
            catch(Exception ex){}
            return result;
        }
        #endregion

        #region 4. Xoa thong tin cua dich vu
        public static bool DeleteDichVu(String maDichVu)
        {
            bool result = false;
            try
            {
                SQLConnect cnn = new SQLConnect();
                List<SqlParameter> sqlPara = new List<SqlParameter>();
                sqlPara.Add(new SqlParameter("@maDichVu", maDichVu));

                int n = cnn.ExecuteNonQuery("",CommandType.StoredProcedure,sqlPara);
                if (n == 1)
                {
                    result = true;
                }
            }
            catch(Exception ex){}
            return result;
        }

        #endregion

        #region 5. Cap nhat thong tin dich vu
        public static bool UpdateDichVu(DichVuDTO dv)
        {
            bool result = false;
            try
            {

            }
            catch(Exception ex){}
            return result;
        }
        #endregion

        #region 6. Lay thong tin dich vu theo ten
        #endregion
    }
}